package com.Blog.www.dao.Impl;

import com.Blog.www.dao.ColumnDao;
import com.Blog.www.po.Column;
import com.Blog.www.utils.SqlDao;

import java.util.List;

/**
 * 实现类
 *
 * @author 君未洋
 */
public class ColumnDaoImpl implements ColumnDao {
    private static SqlDao dao = new SqlDao();

    @Override
    public int getCount(String prior) {
        String sql = "select count(*) as count from xcolumn where prior=?";
        return dao.selectCount(sql, prior);
    }

    @Override
    public List<Column> findColumnList(int start, int rows, String prior) {
        String sql = "select * from xcolumn where prior = ? limit ? , ?";
        return dao.selectColumn(sql, prior, start, rows);
    }

    @Override
    public Boolean addBlogColumn(String prior, String content) {
        String sql = "insert into xcolumn values (null,?,?)";
        return dao.update(sql, content, prior);
    }

    @Override
    public Boolean deleteBlogColumn(int id) {
        String sql = "delete from xcolumn where id = ?";
        if (dao.update(sql, id)) {
            sql = "delete from blogcolumn where columnid = ?";
            return dao.update(sql, id);
        } else {
            return false;
        }
    }

    @Override
    public Boolean addColumn(String id, String bid) {
        String sql = "insert into blogcolumn values (null,?,?)";
        return dao.update(sql, bid, id);
    }

    @Override
    public Boolean deleteColumn(String bid) {
        String sql = "delete from blogcolumn where blogid = ?";
        return dao.update(sql, bid);
    }

    @Override
    public Column findColumn(String addColumn) {
        String sql = "select * from xcolumn where name = ?";
        List<Column> columns = dao.selectColumn(sql, addColumn);
        if (columns == null || columns.size() == 0) {
            return null;
        } else {
            return columns.get(0);
        }
    }

}
